import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'sppiTestRecordM',
  state: {},
  effects: {
    // 获取列表信息
    *queryByPage({ payload, callback }, { call, put }) {
      const response = yield call(api.sppiTestRecord.queryByPage, payload);

      if (response?.data) {
        callback(response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取列表失败');
      }
    },

    // 新增SPPI记录
    *sppiAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.sppiTestRecord.sppiAdd, payload);
      if (response?.msg == '成功') {
        callback(response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '编辑失败');
      }
    },

    // 获取列表信息
    *getDetail({ payload, callback }, { call, put }) {
      const response = yield call(api.sppiTestRecord.getDetail, payload);

      if (response?.data) {
        callback('success', response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取详情失败');
      }
    },

    // 获取配置
    *queryConf({ payload, callback }, { call, put }) {
      const response = yield call(api.sppiTestRecord.queryConf, payload);

      if (response?.data) {
        callback(response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取配置详情失败');
      }
    },
    // 获取配置
    *updateConf({ payload, callback }, { call, put }) {
      const response = yield call(api.sppiTestRecord.updateConf, payload);

      if (response) {
        callback(response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取配置详情失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
